import Koa from 'koa'
import {
    resolve
} from 'path'
import R from 'ramda'
import mongooseMethods from './database/init'

const MIDDLEWARES = ['common','router']

const useMiddlewares = (app) => {
    R.map(
        R.compose(
            R.forEachObjIndexed(
                initWith => initWith(app)
            ), 
            require,
             name => resolve(__dirname, `./middlewares/${name}`)
            )
        
    )(MIDDLEWARES)
   
}

;(async () => {
    await mongooseMethods.connect()
    mongooseMethods.initSchema()
    await mongooseMethods.initAdmin()
    //require('./tasks/qiniu.js')
    const app = new Koa();
   await useMiddlewares(app)
    app.listen('8002', () => {
        console.log('8002端口已经启动了')
    })
})()